package com.indusfo.spc.client.service.impl;

import com.indusfo.spc.client.mapper.ClientAnoDetailMapper;
import com.indusfo.spc.client.mapper.ClientAnoMapper;
import com.indusfo.spc.client.mapper.ClientBatchFlowFinishMapper;
import com.indusfo.spc.client.mapper.ClientBatchMapper;
import com.indusfo.spc.client.mapper.ClientOrderBadphenoMapper;
import com.indusfo.spc.client.mapper.ClientOrderBomMapper;
import com.indusfo.spc.client.mapper.ClientOrderDeteMapper;
import com.indusfo.spc.client.mapper.ClientOrderFlowMapper;
import com.indusfo.spc.client.mapper.ClientOrderRepairDeteMapper;
import com.indusfo.spc.client.mapper.ClientOrderRepairMapper;
import com.indusfo.spc.client.mapper.ClientOrderStationMapper;
import com.indusfo.spc.client.mapper.ClientOrderTechMapper;
import com.indusfo.spc.client.mapper.ClientProMapper;
import com.indusfo.spc.client.pojo.ClientAno;
import com.indusfo.spc.client.pojo.ClientAnoDetail;
import com.indusfo.spc.client.service.ClientAnoService;
import com.indusfo.spc.exception.BusinessException;
import com.indusfo.spc.exception.GlobalException;
import com.indusfo.spc.exception.ModifyFailedException;
import com.indusfo.spc.exception.ParamsErrorException;
import com.indusfo.spc.mapper.OrderBadphenoMapper;
import com.indusfo.spc.mapper.OrderBomMapper;
import com.indusfo.spc.mapper.OrderDeteMapper;
import com.indusfo.spc.mapper.OrderFlowMapper;
import com.indusfo.spc.mapper.OrderRepairDeteMapper;
import com.indusfo.spc.mapper.OrderRepairFlowMapper;
import com.indusfo.spc.mapper.OrderRepairMapper;
import com.indusfo.spc.mapper.OrderStationMapper;
import com.indusfo.spc.mapper.OrderTechMapper;
import com.indusfo.spc.pojo.Batch;
import com.indusfo.spc.pojo.OrderBadpheno;
import com.indusfo.spc.pojo.OrderBom;
import com.indusfo.spc.pojo.OrderDete;
import com.indusfo.spc.pojo.OrderFlow;
import com.indusfo.spc.pojo.OrderRepair;
import com.indusfo.spc.pojo.OrderRepairDete;
import com.indusfo.spc.pojo.OrderRepairFlow;
import com.indusfo.spc.pojo.OrderStation;
import com.indusfo.spc.pojo.OrderTech;
import com.indusfo.spc.service.BarCodeRules;
import com.indusfo.spc.vo.JSONObject;

import org.hibernate.QueryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ClientAnoServiceImpl implements ClientAnoService {

	private static final Logger logger = LoggerFactory.getLogger(ClientAnoServiceImpl.class);

	@Resource
	private ClientAnoMapper clientAnoMapper;

	@Resource
	private ClientAnoDetailMapper clientAnoDetailMapper;
	@Resource
	private OrderTechMapper orderTechMapper;
	@Resource
	private ClientOrderFlowMapper clientOrderFlowMapper;
	@Resource
	private OrderFlowMapper orderFlowMapper;
	@Resource
	private ClientOrderStationMapper clientOrderStationMapper;
	@Resource
	private OrderStationMapper orderStationMapper;
	@Resource
	private ClientOrderDeteMapper clientOrderDeteMapper;
	@Resource
	private OrderDeteMapper orderDeteMapper;
	@Resource
	private ClientOrderBomMapper clientOrderBomMapper;
	@Resource
	private OrderBomMapper orderBomMapper;
	@Resource
	private ClientOrderBadphenoMapper clientOrderBadphenoMapper;
	@Resource
	private OrderBadphenoMapper orderBadphenoMapper;
	@Resource
	private ClientOrderRepairMapper clientOrderRepairMapper;
	@Resource
	private OrderRepairMapper orderRepairMapper;
	@Resource
	private ClientOrderTechMapper clientOrderTechMapper;
	@Resource
	private ClientOrderRepairDeteMapper clientOrderRepairDeteMapper;
	@Resource
	private OrderRepairDeteMapper orderRepairDeteMapper;
	@Resource
	private OrderRepairFlowMapper orderRepairFlowMapper;
	@Resource
	private ClientBatchMapper clientBatchMapper;
	@Resource
	private BarCodeRules barCodeRules;
	@Resource
	private ClientProMapper clientProMapper;
	@Resource
	private ClientBatchFlowFinishMapper clientBatchFlowFinishMapper;

	@Override
	public JSONObject selectClientAno(ClientAno clientAno) {
		List<ClientAno> clientAnoList = null;
		int count = 0;
		try {
			Integer pagesize = clientAno.getPagesize();
			Integer pageindex = clientAno.getPageindex();
			if (pagesize != null && pageindex != null) {
				clientAno.setIncept(pagesize * (pageindex - 1));
			}
			clientAnoList = clientAnoMapper.selectClientAno(clientAno);
			// 查询分页总记录数
			count = clientAnoMapper.countClientAno(clientAno); // 返回查询到的总记录数
			if (clientAnoList.isEmpty()) {
				return JSONObject.oK("没有查询到相关数据", clientAnoList, count);
			}
			return JSONObject.oK("查询成功", clientAnoList, count);
		} catch (GlobalException e) {
			logger.error(e.getMessage(), e);
			return JSONObject.build(403, e.getMessage());
		}
	}

	@Override
	public JSONObject queryClientAnoDetail(ClientAnoDetail clientAnoDetail) {
		List<ClientAnoDetail> clientAnoDetailList = null;
		int count = 0;
		try {
			Integer pagesize = clientAnoDetail.getPagesize();
			Integer pageindex = clientAnoDetail.getPageindex();
			if (pagesize != null && pageindex != null) {
				clientAnoDetail.setIncept(pagesize * (pageindex - 1));
			}
			clientAnoDetailList = clientAnoDetailMapper.selectClientAnoDetail(clientAnoDetail);
			// 查询分页总记录数
			count = clientAnoDetailMapper.countClientAnoDetail(clientAnoDetail);
			if (clientAnoDetailList.isEmpty()) {
				return JSONObject.oK("没有查询到相关数据", clientAnoDetailList, count);
			}
			return JSONObject.oK("查询成功", clientAnoDetailList, count);
		} catch (GlobalException e) {
			logger.error(e.getMessage(), e);
			return JSONObject.build(403, e.getMessage());
		}
	}

	/**
	 * 不良保存
	 */
	@Override
	@Transactional
	public String insertClientAno(ClientAno clientAno) {
		// 判定不良现象集合是否为空
		if (clientAno.getClientAnoDetails().isEmpty()) {
			throw new ParamsErrorException("不良现象不能为空！");
		}
		// 判断后面工序是否已开工或已完工
		Integer serialNum = clientBatchFlowFinishMapper.selectLastSerialNumByBatchId(clientAno.getBatchId());
		if (serialNum > clientAno.getSerialNum()) {
			throw new BusinessException("后续工序已开工，无法再提交不良！");
		}
		// 查询当前批次未处理完的不良单
		ClientAno untreatedClientAno = clientAnoMapper.queryUntreatedClientAnoId(clientAno.getBatchId());
		Integer clientAnoId = null;
		if (untreatedClientAno == null) {
			// 生成不良单编号
			List<String> calculate = barCodeRules.calculate(30, 1);
			clientAno.setClientAnoNo(calculate.get(0));
			clientAno.setSflag("工检");
			clientAno.setAnoState(1);
			// 保存不良记录并返回主键ID
			Integer count = clientAnoMapper.insertClientAno(clientAno);
			if (count == 0) {
				throw new ModifyFailedException("新增失败！");
			}
			clientAnoId = clientAno.getClientAnoId();
		} else {
			clientAnoId = untreatedClientAno.getClientAnoId();
		}
		List<ClientAnoDetail> clientAnoDetails = clientAno.getClientAnoDetails();
		// 查询是否有未完成的不良现象
		List<Integer> badphenoIds = clientAnoDetailMapper.queryBadphenoIdByClientAnoId(clientAnoId);
		// 如果有未完成的不良现象就进行去重
		if (!badphenoIds.isEmpty()) {
			clientAnoDetails = clientAnoDetails.stream().filter(o -> !badphenoIds.contains(o.getBadphenoId()))
					.collect(Collectors.toList());
		}
		// 如果有不良现象则保存
		if (!clientAnoDetails.isEmpty()) {
			// 将主键ID设置到每个子记录中
			for (ClientAnoDetail clientAnoDetail : clientAnoDetails) {
				clientAnoDetail.setClientAnoId(clientAnoId);
			}
			// 保存不良现象
			Integer count = clientAnoDetailMapper.insertClientAnoDetail(clientAnoDetails);
			if (count != clientAnoDetails.size()) {
				throw new ModifyFailedException("新增不良现象失败！");
			}
		}
		// 通过批次ID查询任务单版本
		Batch batch = clientBatchMapper.selectByBatchId(clientAno.getBatchId());
		if (null == batch) {
			throw new QueryException("未查到对应批次！");
		}
		Integer oldOrderTechId = batch.getOrderTechId();
		if (null == oldOrderTechId) {
			throw new QueryException("未查到该批次下任务单版本！");
		}
		String msg = "不良信息提交成功！";
		// 判断是否为下线工站
		if (clientAno.getIsOffLineStation()) {
			// 判断是否已经插入维修工序
			Integer proTypeId = clientProMapper.queryNextProTypeIdByBatchId(batch.getBatchId());
			if (proTypeId == null || proTypeId != 3) {
				msg = insertRepair(batch.getBatchId(), batch.getOrderId(), oldOrderTechId, clientAno.getOrderFlowId(),
						clientAno.getUserId());
			}
		}
		return msg;
	}

	/**
	 * 插入维修工序
	 * 
	 * @param batchId
	 * @param orderId
	 * @param oldOrderTechId
	 * @param orderFlowId
	 * @param userId
	 */
	@Override
	public String insertRepair(Integer batchId, Integer orderId, Integer oldOrderTechId, Integer orderFlowId,
			Integer userId) {
		String msg = "";
		// 查询当前下线工站的维修工序
		List<Integer> repairPros = clientAnoMapper.queryRepairProByOrderFlowId(orderFlowId, oldOrderTechId);
		if (repairPros.isEmpty()) {
			msg = "不良信息提交成功！此工站没有维修工序，下线失败！";
		} else {
			Integer orderTechId = oldOrderTechId;
			// 查询当前流程版本是否是独立的
			Integer sourceTypeId = clientOrderTechMapper.selectSourceTypeIdByBatchId(batchId);
			if (sourceTypeId == 1) {
				// 如果是不独立的版本则生成新流程版本
				OrderTech orderTech = new OrderTech();
				orderTech.setOrderId(orderId);
				orderTech.setSourceTypeId(2);
				orderTech.setUserId(userId);
				orderTech.setDataState(1);
				Integer count = orderTechMapper.insertOrderTech(orderTech);
				if (count == 0) {
					throw new ModifyFailedException("新增失败！");
				}
				orderTechId = orderTech.getOrderTechId();
				// 查询所有旧流程
				List<OrderFlow> orderFlows = clientOrderFlowMapper.selectByOrderTechId(oldOrderTechId);
				// 复制流程和维修
				copyOrderFlows(orderFlows, orderTechId, oldOrderTechId);
			}
			// 查询当前流程所有工序
			List<OrderFlow> newOrderFlows = clientOrderFlowMapper.selectByOrderTechId(orderTechId);
			// 查询当前工序点
			OrderFlow nowOrderFlow = clientOrderFlowMapper.selectByOrderFlowId(orderFlowId);
			// 声明新序号
			Integer serialNum = 1;
			// 插入维修工序并排序
			for (OrderFlow orderFlow : newOrderFlows) {
				orderFlow.setSerialNum(serialNum);
				// 更新
				orderFlowMapper.updateOrderFlow(orderFlow);
				serialNum++;
				// 判断当前工序是否已完工
				if (orderFlow.getSerialNum() == nowOrderFlow.getSerialNum()) {
					// 循环插入维修工序
					for (int i = 0; i < repairPros.size(); i++) {
						OrderFlow repairOrderFlow = new OrderFlow();
						repairOrderFlow.setOrderTechId(orderFlow.getOrderTechId());
						repairOrderFlow.setProId(repairPros.get(i));
						repairOrderFlow.setSerialNum(serialNum);
						repairOrderFlow.setSequence(0);
						repairOrderFlow.setDataState(1);
						Integer count = orderFlowMapper.insertOrderFlow(repairOrderFlow);
						if (count == 0) {
							throw new BusinessException("插入维修工序失败！");
						}
						Integer nowOrderFlowId = repairOrderFlow.getOrderFlowId();
						// 插入维修采集到采集表
						// 根据任务单版本ID和工序查询关联维修采集参数信息
						List<OrderRepairDete> orderRepairDetes = clientOrderRepairDeteMapper
								.selectOrderRepairDeteByOrderTechIdAndProId(orderFlow.getOrderTechId(),
										repairPros.get(i));
						if (!orderRepairDetes.isEmpty()) {
							// 循环将新任务单流程ID设置进去并保存
							for (OrderRepairDete orderRepairDete : orderRepairDetes) {
								OrderDete orderDete = new OrderDete();
								orderDete.setOrderFlowId(nowOrderFlowId);
								orderDete.setDeteId(orderRepairDete.getDeteId());
								orderDete.setUpperLimit(orderRepairDete.getUpperLimit());
								orderDete.setLowerLimit(orderRepairDete.getLowerLimit());
								orderDete.setMiddleLimit(orderRepairDete.getMiddleLimit());
								orderDete.setSerialNum(orderRepairDete.getSerialNum());
								orderDete.setSampleNum(orderRepairDete.getSampleNum());
								orderDete.setSampleCount(orderRepairDete.getSampleCount());
								orderDete.setShowDete(orderRepairDete.getShowDete());
								orderDete.setDataState(1);
								count = orderDeteMapper.insertOrderDete(orderDete);
								if (count == 0) {
									throw new ModifyFailedException("复制维修采集数据失败！");
								}
							}
						}
						serialNum++;
						if (i == 0) {
							// 更新批次表信息
							Batch updateBatch = new Batch();
							updateBatch.setBatchId(batchId);
							updateBatch.setOrderFlowId(nowOrderFlowId);
							updateBatch.setOrderTechId(orderTechId);
							// 修改状态为待投产状态
							updateBatch.setOrderFlowStateId(1);
							count = clientBatchMapper.updateBatch(updateBatch);
							if (count == 0) {
								throw new BusinessException("更新批次记录失败！");
							}
						}
					}
				}
			}
			msg = "不良品送修成功！";
		}
		return msg;
	}

	/**
	 * 复制流程
	 * 
	 * @param oldOrderTechId
	 * @param newOrderTechId
	 * @return
	 */
	public void copyOrderFlows(List<OrderFlow> orderFlows, Integer newOrderTechId, Integer oldOrderTechId) {
		// 用于存放维修主表，去重用
		HashMap<Integer, Integer> map = new HashMap<>();
		// 复制流程相关数据
		for (OrderFlow orderFlow : orderFlows) {
			Integer oldOrderFlowId = orderFlow.getOrderFlowId();
			OrderFlow newOrderFlow = new OrderFlow();
			newOrderFlow.setOrderTechId(newOrderTechId);
			newOrderFlow.setProId(orderFlow.getProId());
			newOrderFlow.setSerialNum(orderFlow.getSerialNum());
			newOrderFlow.setSequence(orderFlow.getSequence());
			newOrderFlow.setDataState(1);
			// 保存新流程
			Integer count = orderFlowMapper.insertOrderFlow(newOrderFlow);
			Integer newOrderFlowId = newOrderFlow.getOrderFlowId();
			if (count == 0) {
				throw new ModifyFailedException("复制流程失败！");
			}
			// 复制其它关联数据
			// 1工位po_order_station
			copyOrderStations(oldOrderFlowId, newOrderFlowId);
			// 2采集参数po_order_dete
			copyOrderDetes(oldOrderFlowId, newOrderFlowId);
			// 3关键物料po_order_bom
			copyOrderBoms(oldOrderFlowId, newOrderFlowId);
			// 4不良现象po_order_badpheno
			copyOrderBadphenos(oldOrderFlowId, newOrderFlowId);
			// 查询维修流程表中老流程是否有记录
			OrderRepair orderRepair = clientOrderRepairMapper.selectOrderRepairByOrderFlowId(oldOrderFlowId);
			if (orderRepair != null) {
				// 老维修ID
				Integer oldOrderRepairId = orderRepair.getOrderRepairId();
				// 如果是新版本
				if (!newOrderTechId.equals(oldOrderTechId)) {
					// 判断map里有没有重复的数据
					if (!map.containsKey(orderRepair.getRepairId())) {
						// 5维修po_order_repair
						// 将新任务单版本ID设置进去并保存
						OrderRepair newOrderRepair = new OrderRepair();
						newOrderRepair.setRepairId(orderRepair.getRepairId());
						newOrderRepair.setOrderTechId(newOrderTechId);
						newOrderRepair.setDataState(1);
						count = orderRepairMapper.insertOrderRepair(newOrderRepair);
						if (count == 0) {
							throw new ModifyFailedException("复制维修失败！");
						}
						// 将新维修ID存入map
						map.put(orderRepair.getRepairId(), newOrderRepair.getOrderRepairId());
					}
					// 复制维修流程
					copyOrderRepairFlows(map.get(orderRepair.getRepairId()), newOrderFlowId);
					// 复制维修采集数据
					copyOrderRepairDetes(oldOrderRepairId, map.get(orderRepair.getRepairId()));
				} else {
					// 复制维修流程
					copyOrderRepairFlows(oldOrderRepairId, newOrderFlowId);
				}
			}
		}
	}

	/**
	 * 复制工位
	 * 
	 * @param oldOrderFlowId
	 * @param newOrderFlowId
	 * @return
	 */
	public void copyOrderStations(Integer oldOrderFlowId, Integer newOrderFlowId) {
		// 根据老任务单流程ID查询关联工位信息
		List<OrderStation> orderStations = clientOrderStationMapper.selectByOrderFlowId(oldOrderFlowId);
		if (!orderStations.isEmpty()) {
			// 循环将新任务单流程ID设置进去并保存
			for (OrderStation orderStation : orderStations) {
				OrderStation newOrderStation = new OrderStation();
				newOrderStation.setOrderFlowId(newOrderFlowId);
				newOrderStation.setStationId(orderStation.getStationId());
				newOrderStation.setDataState(1);
				Integer count = orderStationMapper.insertOrderStation(newOrderStation);
				if (count == 0) {
					throw new ModifyFailedException("复制工位失败！");
				}
			}
		}
	}

	/**
	 * 复制采集参数
	 * 
	 * @param oldOrderFlowId
	 * @param newOrderFlowId
	 * @return
	 */
	public void copyOrderDetes(Integer oldOrderFlowId, Integer newOrderFlowId) {
		// 根据老任务单流程ID查询关联采集参数信息
		List<OrderDete> orderDetes = clientOrderDeteMapper.selectByOrderFlowId(oldOrderFlowId);
		if (!orderDetes.isEmpty()) {
			// 循环将新任务单流程ID设置进去并保存
			for (OrderDete orderDete : orderDetes) {
				OrderDete newOrderDete = new OrderDete();
				newOrderDete.setOrderFlowId(newOrderFlowId);
				newOrderDete.setDeteId(orderDete.getDeteId());
				newOrderDete.setUpperLimit(orderDete.getUpperLimit());
				newOrderDete.setLowerLimit(orderDete.getLowerLimit());
				newOrderDete.setMiddleLimit(orderDete.getMiddleLimit());
				newOrderDete.setSerialNum(orderDete.getSerialNum());
				newOrderDete.setSampleNum(orderDete.getSampleNum());
				newOrderDete.setShowDete(orderDete.getShowDete());
				newOrderDete.setSampleCount(orderDete.getSampleCount());
				newOrderDete.setDataState(1);
				Integer count = orderDeteMapper.insertOrderDete(newOrderDete);
				if (count == 0) {
					throw new ModifyFailedException("复制采集参数失败！");
				}
			}
		}
	}

	/**
	 * 复制关键物料
	 * 
	 * @param oldOrderFlowId
	 * @param newOrderFlowId
	 * @return
	 */
	public void copyOrderBoms(Integer oldOrderFlowId, Integer newOrderFlowId) {
		// 根据老任务单流程ID查询关联关键物料信息
		List<OrderBom> orderBoms = clientOrderBomMapper.selectByOrderFlowId(oldOrderFlowId);
		if (!orderBoms.isEmpty()) {
			// 循环将新任务单流程ID设置进去并保存
			for (OrderBom orderBom : orderBoms) {
				OrderBom newOrderBom = new OrderBom();
				newOrderBom.setOrderFlowId(newOrderFlowId);
				newOrderBom.setMatId(orderBom.getMatId());
				newOrderBom.setReduceTypeId(orderBom.getReduceTypeId());
				newOrderBom.setReduceNum(orderBom.getReduceNum());
				newOrderBom.setKeyMaterial(orderBom.getKeyMaterial());
				newOrderBom.setDataState(1);
				Integer count = orderBomMapper.insertOrderBom(newOrderBom);
				if (count == 0) {
					throw new ModifyFailedException("复制关键物料失败！");
				}
			}
		}
	}

	/**
	 * 复制不良现象
	 * 
	 * @param oldOrderFlowId
	 * @param newOrderFlowId
	 * @return
	 */
	public void copyOrderBadphenos(Integer oldOrderFlowId, Integer newOrderFlowId) {
		// 根据老任务单流程ID查询关联不良现象信息
		List<OrderBadpheno> orderBadphenos = clientOrderBadphenoMapper.selectByOrderFlowId(oldOrderFlowId);
		if (!orderBadphenos.isEmpty()) {
			// 循环将新任务单流程ID设置进去并保存
			for (OrderBadpheno orderBadpheno : orderBadphenos) {
				OrderBadpheno newOrderBadpheno = new OrderBadpheno();
				newOrderBadpheno.setOrderFlowId(newOrderFlowId);
				newOrderBadpheno.setBadphenoId(orderBadpheno.getBadphenoId());
				newOrderBadpheno.setDataState(1);
				Integer count = orderBadphenoMapper.insertOrderBadpheno(newOrderBadpheno);
				if (count == 0) {
					throw new ModifyFailedException("复制不良现象失败！");
				}
			}
		}
	}

	/**
	 * 复制维修流程
	 * 
	 * @param newOrderRepairId
	 * @param orderFlowId
	 * @return
	 */
	public void copyOrderRepairFlows(Integer newOrderRepairId, Integer orderFlowId) {
		// 6维修流程po_order_repair_flow
		OrderRepairFlow newOrderRepairFlow = new OrderRepairFlow();
		newOrderRepairFlow.setOrderRepairId(newOrderRepairId);
		newOrderRepairFlow.setOrderFlowId(orderFlowId);
		newOrderRepairFlow.setDataState(1);
		Integer count = orderRepairFlowMapper.insertOrderRepairFlow(newOrderRepairFlow);
		if (count == 0) {
			throw new ModifyFailedException("复制维修流程失败！");
		}
	}

	/**
	 * 复制维修采集数据
	 * 
	 * @param oldOrderRepairId
	 * @param newOrderRepairId
	 * @return
	 */
	public void copyOrderRepairDetes(Integer oldOrderRepairId, Integer newOrderRepairId) {
		// 7维修采集参数po_order_repair_dete
		// 根据老任务单流程ID查询关联维修采集参数信息
		List<OrderRepairDete> orderRepairDetes = clientOrderRepairDeteMapper
				.selectOrderRepairDeteByOrderRepairId(oldOrderRepairId);
		if (!orderRepairDetes.isEmpty()) {
			// 循环将新任务单流程ID设置进去并保存
			for (OrderRepairDete orderRepairDete : orderRepairDetes) {
				OrderRepairDete newOrderRepairDete = new OrderRepairDete();
				newOrderRepairDete.setOrderRepairId(newOrderRepairId);
				newOrderRepairDete.setRepairDetailId(orderRepairDete.getRepairDetailId());
				newOrderRepairDete.setDeteId(orderRepairDete.getDeteId());
				newOrderRepairDete.setUpperLimit(orderRepairDete.getUpperLimit());
				newOrderRepairDete.setLowerLimit(orderRepairDete.getLowerLimit());
				newOrderRepairDete.setMiddleLimit(orderRepairDete.getMiddleLimit());
				newOrderRepairDete.setSerialNum(orderRepairDete.getSerialNum());
				newOrderRepairDete.setSampleNum(orderRepairDete.getSampleNum());
				newOrderRepairDete.setSampleCount(orderRepairDete.getSampleCount());
				newOrderRepairDete.setShowDete(orderRepairDete.getShowDete());
				newOrderRepairDete.setDataState(1);
				Integer count = orderRepairDeteMapper.insertOrderRepairDete(newOrderRepairDete);
				if (count == 0) {
					throw new ModifyFailedException("复制维修采集数据失败！");
				}
			}
		}
	}
}
